package order.service.service;

import order.service.mapper.OrderMapper;
import order.service.model.OrderInfo;
import order.service.model.ProductInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

@Service
public class OrderService {
    @Autowired
    OrderMapper orderMapper;
    @Autowired
    RestTemplate restTemplate;
    public OrderInfo getOrderInfoById(Integer id) {
        OrderInfo orderInfo = orderMapper.getOrderInfoById(id);
        String url = "http://product-server/product/" + orderInfo.getProductId();
        ProductInfo productInfo = restTemplate.getForObject(url, ProductInfo.class);
        System.out.println(productInfo);
        orderInfo.setProductInfo(productInfo);
        return orderInfo;
    }
}
